<?php
class RelatedPosts extends CWidget {
	public $category;
	public $posts;
	public $post;

	public function init() {
		$post = $this->post;
		$this->category = $post->categories[0]->terms;
		$criteria = new CDbCriteria;
		$criteria->order = 'postId DESC';
		$this->posts = Posts::model()->section()->findByCategoryId($this->category->taxonomy[0]->termTaxonomyId, $criteria);
	}
	
	public function run() {
		$this->renderContent();
	}
	
	public function renderContent() {
		
		$this->render('related-posts', array('posts' => $this->posts));
	}
}